import apis from "../../../api/apis";

export default {
    namespaced: true,
    state: {
        pageSize: 3,
        pages: 0,
        total: 0,
        pageNum: 1,
        currentPage: 1,
        value: '',
        appointment: [],
    },
    mutations: {
        setData(state, newData) {
            state.pages = newData.pages;
            state.total = newData.total;
            state.appointment = newData.data
        },
        setCurrentPage(state, currentPage) {
            state.currentPage = currentPage;
        }
    },
    actions: {
        async getAppointment(context, state) {

            // const data = await apis.appointment.getAppointment({
            //   pageSize:context.state.pageSize,
            //   currentPage:context.state.currentPage,
            //   data:{
            //      state
            //   }
            //     });
            const data = await apis.appointment.getAppointment({
                pageSize: context.state.pageSize,
                currentPage: context.state.currentPage,
                data: {
                    ...state
                }
            });

            if (data.data.code === 200) {
                context.commit('setData', data.data.data)
            }

        },
        async updateReservation(context, reservation) {
            return apis.appointment.updateReservation(reservation);
        },
        async deleteReservation(context, id) {
            return apis.appointment.deleteReservation(id);
        }
    }
}